import requests

# 响应内容为文本, 使用text属性.

url = 'http://localhost/smeoa/index.php?m=login&a=index'
# 建立一个Get的连接对象
# r = requests.request('get', url)
r = requests.get(url)
# 获取响应
resp = r.text
# print(resp)


# 响应如果是json, 使用json方法.
# 按照字典和列表的方式来处理就成.
url = 'http://127.0.0.1:8000/api/get_event_list/?eid=1'
r = requests.get(url)
resp = r.json()
print(resp)
print(resp['message'])
print(resp['data']['eid'])

url = 'https://www.baidu.com/img/bd_logo1.png'
r = requests.get(url)
# 如果是二进制数据, 使用content属性
print(r.content)
with open('../bd_logo.jpg', 'wb') as f:
    f.write(r.content)
